package com.ys.erp.stage_marketing_service.controller;

import com.alibaba.fastjson2.JSONObject;
import com.ys.erp.framework.annotation.CheckEmpLogin;
import com.ys.erp.framework.annotation.ResponseResult;
import com.ys.erp.framework.annotation.StageLoginEmp;
import com.ys.erp.framework.bean.dto.StageEmpDTO;
import com.ys.erp.framework.response.PageDTO;
import com.ys.erp.framework.response.ResponseDTO;
import com.ys.erp.stage_marketing_service.bean.condition.ActivityTurntableCondition;
import com.ys.erp.stage_marketing_service.bean.vo.*;
import com.ys.erp.stage_marketing_service.service.ActivityTurntableService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * @author 南山
 * @date 2025/09/19 17:21
 */
@ResponseResult
@RestController
@RequiredArgsConstructor
@RequestMapping("/manage/marketing/turntable")
@Tag(name = "ActivityTurntableController", description = "营销中心转盘活动相关接口")
public class ActivityTurntableController {

    private final ActivityTurntableService activityTurntableService;

    @PostMapping("/getActivityTurntablePage")
    @Operation(summary = "获取转盘活动分页列表", description = "获取转盘活动分页列表")
    @CheckEmpLogin
    public PageDTO<ActivityTurntableVO> getActivityTurntablePage(@RequestBody @Valid ActivityTurntableCondition.PageActivityTurntableCon con, @StageLoginEmp StageEmpDTO emp) {
        return activityTurntableService.getActivityTurntablePage(emp, con);
    }


    @PostMapping("/addOrUpdateActivityTurntable")
    @Operation(summary = "添加或更新转盘活动", description = "添加或更新转盘活动")
    @CheckEmpLogin
    public void addOrUpdateActivityTurntable(@RequestBody @Valid ActivityTurntableCondition.AddOrUpdateActivityTurntableCon con, @StageLoginEmp StageEmpDTO emp) {
        activityTurntableService.addOrUpdateActivityTurntable(emp, con);
    }


    @GetMapping("/getActivityTurntableInfo")
    @Operation(summary = "获取转盘活动详情信息", description = "获取转盘活动详情信息")
    @CheckEmpLogin
    public ActivityTurntableInfoVO getActivityTurntableInfo(@RequestParam("activityId") Long activityId, @StageLoginEmp StageEmpDTO emp) {

        return activityTurntableService.getActivityTurntableInfo(emp, activityId);
    }

    @GetMapping("/getActivityTurntablePhysicalGoodsInfo")
    @Operation(summary = "获取转盘活动实物奖品配置回显信息信息", description = "获取转盘活动实物奖品配置回显信息信息")
    @CheckEmpLogin

    public ActivityTurntablePhysicalGoodsInfo getActivityTurntablePhysicalGoodsInfo(@RequestParam("prizedId") Long prizedId, @StageLoginEmp StageEmpDTO emp) {
        return activityTurntableService.getActivityTurntablePhysicalGoodsInfo(emp, prizedId);
    }

    @GetMapping
    @Operation(summary = "获取转盘活动url", description = "获取转盘活动url")
    @CheckEmpLogin
    public ActivityTurntableUrlVO getActivityTurntableUrl(@RequestParam("activityId") Long activityId, @StageLoginEmp StageEmpDTO emp) {
        return activityTurntableService.getActivityTurntableUrl(emp, activityId);
    }

    @GetMapping("/stopActivityTurntable")
    @Operation(summary = "停止转盘活动", description = "停止转盘活动")
    @CheckEmpLogin
    public void stopActivityTurntable(@RequestParam("activityId") Long activityId, @StageLoginEmp StageEmpDTO emp) {
        activityTurntableService.stopActivityTurntable(emp, activityId);
    }

    @PostMapping("/getActivityTurntableJoin")
    @Operation(summary = "获取参与者统计信息", description = "获取参与者统计信息")
    @CheckEmpLogin
    public ActivityTurntableJoinVo getActivityTurntableJoin(@RequestBody ActivityTurntableCondition.GetActivityTurntableJoinUserPage con, @StageLoginEmp StageEmpDTO emp) {
        return activityTurntableService.getActivityTurntableJoin(emp, con);
    }


    @PostMapping("/getActivityTurntableJoinUserPage")
    @Operation(summary = "获取转盘活动参与者分页列表", description = "获取转盘活动参与者分页列表")
    @CheckEmpLogin
    public PageDTO<ActivityTurntableJoinUserVO> getActivityTurntableJoinUserPage(@RequestBody ActivityTurntableCondition.GetActivityTurntableJoinUserPage con, @StageLoginEmp StageEmpDTO emp) {
        return activityTurntableService.getActivityTurntableJoinUserPage(emp, con);
    }

    @PostMapping("/getActivityTurntableJoinUserPageExcel")
    @Operation(summary = "获取参与者统计信息Excel", description = "获取参与者统计信息Excel")
    @CheckEmpLogin
    public void getActivityTurntableJoinUserPageExcel(@RequestBody ActivityTurntableCondition.GetActivityTurntableJoinUserPage con,
                                                                         @StageLoginEmp StageEmpDTO emp,
                                                                         HttpServletResponse response) throws IOException {
        activityTurntableService.getActivityTurntableJoinUserPageExcel(emp, con, response);
    }


    @PostMapping("/getActivityTurntableWinner")
    @Operation(summary = "获取转盘活动中奖信息统计", description = "获取转盘活动中奖信息")
    @CheckEmpLogin
    public List<ActivityTurntableWinnerVO> getActivityTurntableWinner(@RequestBody ActivityTurntableCondition.GetActivityTurntableWinnerPage con, @StageLoginEmp StageEmpDTO emp) {
        return activityTurntableService.getActivityTurntableWinner(emp, con);
    }


    @PostMapping("/getActivityTurntableWinnerPage")
    @Operation(summary = "获取转盘活动中奖用户分页列表", description = "获取转盘活动中奖用户分页列表")
    @CheckEmpLogin
    public PageDTO<ActivityTurntableWinnerUserVO> getActivityTurntableWinnerPage(@RequestBody ActivityTurntableCondition.GetActivityTurntableWinnerPage con, @StageLoginEmp StageEmpDTO emp) {
        return activityTurntableService.getActivityTurntableWinnerPage(emp, con);
    }

    @PostMapping("/getActivityTurntableWinnerPageExcel")
    @Operation(summary = "获取转盘活动中奖用户分页列表导出", description = "获取转盘活动中奖用户分页列表导出")
    @CheckEmpLogin
    public void getActivityTurntableWinnerPageExcel(@RequestBody ActivityTurntableCondition.GetActivityTurntableWinnerPage con,
                                                                                      @StageLoginEmp StageEmpDTO emp,
                                                                                      HttpServletResponse response) throws IOException {
        activityTurntableService.getActivityTurntableWinnerPageExcel(emp, con, response);
    }


    @GetMapping("/getActivityTurntableUserWinnerPrizedInfo")
    @Operation(summary = "获取转盘活动用户中奖奖品信息", description = "获取转盘活动用户中奖奖品信息")
    @CheckEmpLogin
    public List<ActivityTurntableUserWinnerPrizedInfo> getActivityTurntableUserWinnerPrizedInfo(@RequestParam("activityId") Long activityId, @RequestParam("userId") Long userId, @StageLoginEmp StageEmpDTO emp) {
        return activityTurntableService.getActivityTurntableUserWinnerPrizedInfo(activityId, userId);
    }


    @PostMapping("/getActivityTurntablePhysicalRedeemPage")
    @Operation(summary = "获取转盘活动实物兑换分页列表", description = "获取转盘活动实物兑换分页列表")
    @CheckEmpLogin
    public PageDTO<ActivityTurntablePhysicalRedeemVO> getActivityTurntablePhysicalRedeemPage(@RequestBody ActivityTurntableCondition.GetActivityTurntablePhysicalRedeemPage con, @StageLoginEmp StageEmpDTO emp) {
        return activityTurntableService.getActivityTurntablePhysicalRedeemPage(emp, con);
    }

    @GetMapping("/getActivityTurntablePhysicalSendInfo")
    @Operation(summary = "获取实物奖励信息", description = "获取实物奖励信息")
    @CheckEmpLogin
    public ActivityTurntablePhysicalSendInfoVO getActivityTurntablePhysicalSendInfo(@RequestParam("redeemRecordId") Long redeemRecordId, @StageLoginEmp StageEmpDTO emp) {
        return activityTurntableService.getActivityTurntablePhysicalSendInfo(emp, redeemRecordId);
    }


    @PostMapping("/physicalSend")
    @Operation(summary = "实物奖励发货接口", description = "实物奖励发货接口")
    @CheckEmpLogin
    public void activityTurntablePhysicalSend(@RequestBody ActivityTurntableCondition.PhysicalSendCon con, @StageLoginEmp StageEmpDTO emp) {
        activityTurntableService.physicalSend(emp, con);
    }


    @GetMapping("/getActivityTurntablePhysicalFreight")
    @Operation(summary = "获取转盘活动实物物流信息", description = "获取转盘活动实物物流信息")
    @CheckEmpLogin
    public List<JSONObject> getActivityTurntablePhysicalFreight(@RequestParam("redeemRecordId") Long redeemRecordId, @StageLoginEmp StageEmpDTO emp) {
        return activityTurntableService.getActivityTurntablePhysicalFreight(emp, redeemRecordId);

    }


}
